#include "AST_QT.h"
#include "Global_Include.h"
#include <tchar.h>
#include <QFileDialog>
#include <amp.h>
#include <cmath>
#include <cstdio>
#include "DiskPart.h"
#include "includes/CreateBcdBoot.h"
#include "includes/inicpp.hpp"
#include "includes/idFile.h"
#include <boost/filesystem.hpp>
#include "MessageBoxTimeOut.h"

long long getFileSize2(const char* fileName);
std::vector<WCHAR> AstGetUsedLetter();

/// <summary>
/// 复制文件
/// </summary>
/// <param name="Src">源文件</param>
/// <param name="Dst">新文件</param>
/// <returns></returns>
bool AstCopyFile(
	std::wstring Src,
	std::wstring Dst
);
std::wstring AstGetFileExtendName(
	std::wstring filePath
);
void RestorePartition(
	WCHAR CreatedPartition,
	WCHAR ShrinkedPartition
);

//#error TODO:1.实装PE创建，2.制作WinPE到AdditionToFinalFile

AST_QT::AST_QT(QWidget* parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);
	ui.MainWindowWidget->setCurrentIndex(0);

	//装填combobox
	AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW]正在初始化界面");
	for (auto PIW : PIWL) {
		ui.comboBox_SystemPartition->addItem(_wstr2qstr(
			std::format(L"{}:\\   总大小：{} 字节", PIW.Letter, PIW.TotalSpace)
		));
	}
	//设置初始指定
	for (int i = 0; i < PIWL.size(); i++) {
		if (PIWL[i].Letter == SystemPartitionLetter) {
			ui.comboBox_SystemPartition->setCurrentIndex(i);
			break;
		}
	}
	for (auto EfiInfo : EspInfomationList) {
		ui.comboBox_EfiPartition->addItem(_wstr2qstr(
			std::format(L"磁盘：{} 分区：{}    {}:\\", EfiInfo->PartitionInfo->DiskNumber, EfiInfo->PartitionInfo->PartitionNumber, EfiInfo->Letter)
		));
	}

	//connect(ui.comboBox_Image, SIGNAL(currentIndexChanged(int)), this, SLOT(comboBoxImageIndexChanged(int)));
	//connect(ui.comboBox_SystemPartition, SIGNAL(currentIndexChanged(int)), this, SLOT(comboBoxSystemPartitionIndexChanged));

	//亮色模式，设置背景色
	if (LightMode) this->setStyleSheet("background-color: rgb(255, 255, 255);");

	//限制窗体大小
	this->setMinimumSize(QSize(1024, 768));
	this->setMaximumSize(QSize(1024, 768));

	std::string WindowTitle = "AZPEP SysRi Tool v2 ";

#ifdef _M_ARM64
	WindowTitle += "ARM64 ";
#elif _M_X64
	WindowTitle += "x64 ";
#else
#error 未知的编译平台，请加入
#endif
	// 设置窗体标题
#ifdef _TARGET_DEBUG
	WindowTitle += "Debug";
#elif _TARGET_BETA
	WindowTitle += "Beta";
#elif _TARGET_STABLE
	WindowTitle += "Stable";
#else
#error 未知的编译配置，请加入
#endif
	this->setWindowTitle(_str2qstr(WindowTitle));

	InitDone = true;
	AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW]初始化界面完成！");
}

AST_QT::~AST_QT()
{}

void AST_QT::PushButtonHomeClick() {
	//打印日志
	AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW]用户选中按钮：“导航栏->首页”");
	ui.MainWindowWidget->setCurrentIndex(0);
	return;
}

void AST_QT::PushButtonRestoreSystemClicked() {
	//打印日志
	AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW]用户选中按钮：“导航栏->重装系统”");
	ui.MainWindowWidget->setCurrentIndex(1);
	return;
}

void AST_QT::PushButtonDownloadSystemClicked() {
	//打印日志
	AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW]用户选中按钮：“导航栏->下载系统”");
	//打印鸣谢
	AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW]感谢“VirtualHotBar”建立的Windows映像下载站网站“WinNew”！");

	//打开网页
	auto Status = ShellExecute(NULL, _T("open"), _T("explorer.exe"), _T("https://winnew.cn/"), NULL, SW_SHOW);

	//<=32视为错误，报错
	if ((int)Status <= 32) {
		AstThrowError_ThrowError(
			ERROR_RUNTIME_OPEN_WEBSITE_FAIL,
			std::format(L"打开网页“{}”失败，WinErr代码：{}", _T("https://winnew.cn/"), GetLastError())
		);
		return;
	}

	return;
}

void AST_QT::PushButtonViewImageFileClicked() {
	AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW][RESTORE]用户选中按钮：“基本选项->浏览”");
	AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW][RESTORE][FILESELECTER]开始选择映像文件");

	//打开映像文件
	QString ImageFilePath = QFileDialog::getOpenFileName(
		this,
		tr("打开映像文件"),
		".\\",
		tr("WIM映像文件(*.wim);;ESD映像文件(*.esd)")
		//tr("WIM映像文件(*.wim)")
	);
	//未选中，返回
	if (ImageFilePath.isEmpty()) {
		AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW][RESTORE][FILESELECTER]用户未选择映像文件");
		return;
	}
	
	AstLog_WriteMessage(
		LogHandle,
		std::format(L"[RUNTIME][QT][MAINWINDOW][RESTORE][FILESELECTER]用户已选择文件“{}”", _qstr2wstr(ImageFilePath))
	);

	//打开了，获取映像信息

	AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW][RESTORE]开始获取映像信息");
	AstLog_WriteMessage(LogHandle, L"[RUNTIME][DISM]初始化DismAPI");

	//初始化DISM服务
	HRESULT hStatus = DismInitialize(DismLogErrorsWarnings, NULL, NULL);
	//处理失败，报错
	if (hStatus != S_OK) {
		AstThrowError_ThrowError(
			ERROR_RUNTIME_DISM_INIT_SERVICE_FAIL,
			std::format(L"初始化DismApi失败！WinErr代码：{}", GetLastError())
		);
		return;
	}
	AstLog_WriteMessage(LogHandle, L"[RUNTIME][DISM]初始化DismAPI成功");

	//使用Dism服务获取映像信息
	AstLog_WriteMessage(
		LogHandle,
		std::format(L"[RUNTIME][DISM]开始获取映像文件“{}”的映像信息", _qstr2wstr(ImageFilePath))
	);
	DismImageInfo* DIL = NULL;		//映像信息
	UINT ImageInfoCount = 0;		//映像数目
	try {
		std::wstringstream ImageFilePathWStream;
		ImageFilePathWStream << _qstr2wstr(ImageFilePath);
		//路径处理
		std::wstring ImageFilePathWA = ImageFilePathWStream.str();
		Replace(ImageFilePathWA, L"/", L"\\");
		/*
		//PCWCHAR TempImageFilePathW = ImageFilePathWStream.str().c_str();
		PCWCHAR TempImageFilePathW = (PCWCHAR)malloc(MAX_PATH);
		ZeroMemory((PVOID)TempImageFilePathW, MAX_PATH);
		auto ImageFilePAthWchart = ImageFilePathWStream.str().c_str();
		memcpy(&TempImageFilePathW, ImageFilePAthWchart, MAX_PATH);
		//TempImageFilePathW = ImageFilePathWStream.str().c_str();
		*/
		//获取映像信息
		hStatus = DismGetImageInfo(
			ImageFilePathWA.c_str(),
			&DIL,
			&ImageInfoCount
		);
		//获取失败，报错
		if (hStatus != S_OK) {
			AstThrowError_ThrowError(
				ERROR_RUNTIME_DISM_INIT_SERVICE_FAIL,
				std::format(L"[RUNTIME][DISM]获取映像文件“{}”的映像信息失败！WinErr代码：{}", _qstr2wstr(ImageFilePath), GetLastError())
			);
			DismShutdown();
			return;
		}

	}
	catch (...) {
		//发现异常，报错
		AstThrowError_ThrowError(
			ERROR_RUNTIME_DISM_INIT_SERVICE_FAIL,
			std::format(L"[RUNTIME][DISM]获取映像文件“{}”的映像信息失败！WinErr代码：{}\n", _qstr2wstr(ImageFilePath), GetLastError())
		);
		DismShutdown();
		return;
	}
	//获取系统信息
	SYSTEM_INFO systemInfo;
	GetSystemInfo(&systemInfo);

	//开始转换信息
	SIIL.clear();
	//遍历转换映像信息
	for (int i = 0; i < ImageInfoCount; i++) {
		//检查是否为客户端操作系统而不是服务器操作系统
		if (*new std::wstring(DIL[i].InstallationType) != L"Client") {
			//是，不加载
			AstLog_WriteWarning(LogHandle, std::format(L"[RUNTIME][DISM]映像 {} 不是客户端系统！不加载到软件中。", i + 1));
			continue;
		}
		//检查映像版本是否与本操作系统相符
		if (DIL[i].Architecture != systemInfo.wProcessorArchitecture) {
			//不符，不加载
			AstLog_WriteWarning(LogHandle, std::format(L"[RUNTIME][DISM]映像 {0} 的处理器架构与当前系统的处理器架构不符合，故不加载到软件中\n映像 {0} 的处理器架构：{1}\n当前系统的处理器架构：{2}", i + 1, DIL[i].Architecture, systemInfo.wProcessorArchitecture));
			continue;
		}

		SIIL.push_back(*new SimpleImageInfo());
		SIIL[SIIL.size()-1].Index = *new int(DIL[i].ImageIndex);							//索引
		SIIL[SIIL.size() - 1].ImageName = *new std::wstring(DIL[i].ImageName);				//映像名称
		SIIL[SIIL.size() - 1].ImageDescription = *new std::wstring(DIL[i].ImageDescription);	//映像描述
		SIIL[SIIL.size() - 1].ProductName = *new std::wstring(DIL[i].ProductName);			//产品名称
		SIIL[SIIL.size() - 1].ImageSize = *new UINT64(DIL[i].ImageSize);						//映像大小
		SIIL[SIIL.size() - 1].EditionId = *new std::wstring(DIL[i].EditionId);				//产品类型

		//版本
		SIIL[SIIL.size() - 1].Version.Major = *new UINT(DIL[i].MajorVersion);
		SIIL[SIIL.size() - 1].Version.Minor = *new UINT(DIL[i].MinorVersion);
		SIIL[SIIL.size() - 1].Version.Build = *new UINT(DIL[i].Build);

		AstLog_WriteDebug(LogHandle, L"----------");
		AstLog_WriteDebug(
			LogHandle,
			std::format(L"[RUNTIME][DISM]索引：{}", SIIL[SIIL.size() - 1].Index)
		);
		AstLog_WriteDebug(
			LogHandle,
			std::format(L"[RUNTIME][DISM]映像名称：{} {}", SIIL[SIIL.size() - 1].ImageName, SIIL[SIIL.size() - 1].EditionId)
		);
		AstLog_WriteDebug(
			LogHandle,
			std::format(L"[RUNTIME][DISM]版本：{}.{}.{}", SIIL[SIIL.size() - 1].Version.Major, SIIL[SIIL.size() - 1].Version.Minor, SIIL[SIIL.size() - 1].Version.Build)
		);
		AstLog_WriteDebug(
			LogHandle,
			std::format(L"[RUNTIME][DISM]映像大小：{} 字节", SIIL[SIIL.size() - 1].ImageSize)
		);
	}
	//是否有可供使用的映像
	if (SIIL.size() == 0) {
		//没有，报错返回
		AstThrowError_ThrowError(
			ERROR_RUNTIME_DISM_NO_AVAIABLE_IMAGE,
			std::format(L"[RUNTIME][DISM]映像文件“{}”中没有可供本操作系统安装的映像，详情请看日志。", _qstr2wstr(ImageFilePath))
		);
		DismShutdown();
		return;
	}

	//成功了，加载映像
	ImageFilePathW = _qstr2wstr(ImageFilePath);


	//实装映像
	ui.comboBox_Image->setEnabled(false);	//先禁用该组件
	ui.comboBox_Image->clear();
	//遍历装填
	for (auto SII : SIIL) {
		ui.comboBox_Image->addItem(
			QString::fromLocal8Bit(_wstr2str(std::format(L"[{}] {} {}.{}.{}", SII.Index, SII.ImageName, SII.Version.Major, SII.Version.Minor, SII.Version.Build)))
		);
	}
	ui.textEdit_ImagePath->setText(QString::fromLocal8Bit(_wstr2str(ImageFilePathW)));
	ui.comboBox_Image->setEnabled(true);

	DismShutdown();
	return;
}

void AST_QT::comboBoxSystemPartitionIndexChanged(int Index) {
	//界面未初始化完成，不执行
	if (!InitDone) return;

	//获取当前项所指的分区信息

	auto PIW = PIWL[ui.comboBox_SystemPartition->currentIndex()];

	//设置信息
	SystemPartitionLetter = *new WCHAR(PIW.Letter);
	SystemPartitionTotalSpace = *new unsigned long long(PIW.TotalSpace);
	AstLog_WriteMessage(LogHandle, std::format(L"[RUNTIME][QT][MAINWINDOW][RESTORE]用户选中“基本选项->重装驱动器”中的驱动器“{}”，总大小：{} 字节", SystemPartitionLetter, SystemPartitionTotalSpace));

	//设置界面
	ui.label_PartitionSize->setText(_wstr2qstr(std::format(L"分区大小：{} 字节", SystemPartitionTotalSpace)));

	/* 驱动器大小检测 */
	//驱动器大小>=映像大小*1.2，正常安装
	if (SystemPartitionTotalSpace >= SIIL[ui.comboBox_Image->currentIndex()].ImageSize * 1.2) {
		AstLog_WriteMessage(LogHandle, std::format(L"[RUNTIME][QT][MAINWINDOW][RESTORE]驱动器“{}”可以重装并正常运行该操作系统！", SystemPartitionLetter));

		//绿色
		/*
		QPalette pe;
		pe.setColor(QPalette::WindowText, Qt::green);
		ui.label->setPalette(pe);
		*/
		ui.label_SetupStatus->setStyleSheet("color: #00ff00;");
		ui.label_SetupStatus->setText(_wstr2qstr(
			std::format(L"驱动器“{}”可以重装并正常运行该操作系统！", SystemPartitionLetter)
		));

		ui.pushButton_CreateEnviorment->setEnabled(true);

	}
	//映像大小<=驱动器大小<映像大小*1.2，警告安装
	else if ((SystemPartitionTotalSpace < SIIL[ui.comboBox_Image->currentIndex()].ImageSize * 1.2) && (SystemPartitionTotalSpace >= SIIL[ui.comboBox_Image->currentIndex()].ImageSize)) {
		AstLog_WriteMessage(LogHandle, std::format(L"[RUNTIME][QT][MAINWINDOW][RESTORE]驱动器“{}”可以安装该操作系统，但由于空间较小，该操作系统可能在重装完成后无法正确运行", SystemPartitionLetter));

		//黄色
		/*
		QPalette pe;
		pe.setColor(QPalette::WindowText, Qt::yellow);
		ui.label->setPalette(pe);
		*/
		ui.label_SetupStatus->setStyleSheet("color: #ffff00;");
		ui.label_SetupStatus->setText(_wstr2qstr(
			std::format(L"驱动器“{}”可以安装该操作系统，但由于空间较小，该操作系统可能在重装完成后无法正确运行", SystemPartitionLetter)
		));

		ui.pushButton_CreateEnviorment->setEnabled(true);
	}
	//驱动器大小<映像大小，阻止安装
	else {
		AstLog_WriteMessage(LogHandle, std::format(L"[RUNTIME][QT][MAINWINDOW][RESTORE]由于空间过小，驱动器“{}”不可以安装该操作系统！", SystemPartitionLetter));

		//红色
		/*
		QPalette pe;
		pe.setColor(QPalette::WindowText, Qt::red);
		ui.label->setPalette(pe);
		*/
		ui.label_SetupStatus->setStyleSheet("color: #ff0000;");
		ui.label_SetupStatus->setText(_wstr2qstr(
			std::format(L"由于空间过小，驱动器“{}”不可以安装该操作系统！", SystemPartitionLetter)
		));

		ui.pushButton_CreateEnviorment->setEnabled(false);
	}
}

void AST_QT::comboBoxImageIndexChanged(int Index) {
	ui.label_ImageSize->setText(_wstr2qstr(
		std::format(L"映像大小：{} 字节", SIIL[ui.comboBox_Image->currentIndex()].ImageSize)
	));
	AstLog_WriteMessage(
		LogHandle,
		std::format(L"[RUNTIME][QT][MAINWINDOW][RESTORE]用户选中“基本选项->映像”中的映像 {}", SIIL[ui.comboBox_Image->currentIndex()].Index)
	);
	this->comboBoxSystemPartitionIndexChanged(1);
}

void AST_QT::pushButtonUnlockPartitionClicked() {
	AstLog_WriteMessage(
		LogHandle,
		L"[RUNTIME][QT][MAINWINDOW][RESTORE]用户选中按钮：“基本信息->解锁分区限制”"
	);

	//弹出警告
	int retCode = MessageBox(
		NULL,
		L"警告：\n\n数据无价，谨慎操作。\n\n您确定要把操作系统重装到除系统驱动器以外的驱动器吗？",
		L"警告",
		MB_ICONQUESTION | MB_YESNO
	);

	if (retCode != IDYES) {
		AstLog_WriteMessage(
			LogHandle,
			L"[RUNTIME][QT][MAINWINDOW][RESTORE]用户不同意解锁分区限制，操作终止。"
		);

		return;
	}
	AstLog_WriteMessage(
		LogHandle,
		L"[RUNTIME][QT][MAINWINDOW][RESTORE]用户同意解锁分区限制"
	);

	ui.comboBox_SystemPartition->setEnabled(true);
	ui.pushButton_UnlockPartition->setVisible(false);

	AstLog_WriteWarning(
		LogHandle,
		L"[RUNTIME][QT][MAINWINDOW][RESTORE]分区限制已解锁！"
	);
}

void AST_QT::comboBoxEfiPartitionIndexChanged(int Index) {
	AstLog_WriteMessage(
		LogHandle,
		std::format(L"[RUNTIME][QT][MAINWINDOW][RESTORE]用户选中“基本选项->EFI驱动器”的驱动器“{}”(此驱动器位于硬盘{}，分区{})", EspInfomationList[Index]->Letter, EspInfomationList[Index]->PartitionInfo->DiskNumber, EspInfomationList[Index]->PartitionInfo->PartitionNumber)
	);
}

void AST_QT::checkBoxCopyLogToDesktopStateChanged(int Checked) {
	/*
	AstLog_WriteMessage(
		LogHandle,
		std::format(L"[RUNTIME][QT][MAINWINDOW][RESTORE]用户改变复选框“高级选项->重装结束后将日志复制到桌面”的勾选状态，当前的状态为：{}", ui.checkBox_CopyLogToDesktop->isChecked()
		)
	);
	*/
}

void AST_QT::comboBoxAfterCreateEnviormentIndexChanged(int Index) {
	AstLog_WriteMessage(
		LogHandle,
		std::format(L"[RUNTIME][QT][MAINWINDOW][RESTORE]用户选中“高级选项->安装后状态”中的选项“{}”",
			_qstr2wstr(ui.comboBox_AfterCreateEnviorment->currentText())
		));
}

void AST_QT::pushButtonCreateEnviormentClicked() {
	AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW][RESTORE]用户选中按钮：“基本选项->配置环境”");
	AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW][RESTORE]正在确认用户是否进一步操作");

	if (
		MessageBox(
			NULL,
			std::format(L"请核对以下信息是否正确：\n\n\n映像路径：{}\n选中映像简略信息：\n映像索引：{}\n映像名称：{}\n映像大小：{} 字节\n\n欲重装驱动器盘符：{}\nEFI分区：位于磁盘{}，硬盘{}，挂载盘符：{}\n\n警告：驱动器“{}”的所有数据都将在重装系统时被不可逆地清除！",
				ImageFilePathW ,
				SIIL[ui.comboBox_Image->currentIndex()].Index, 
				SIIL[ui.comboBox_Image->currentIndex()].ImageName,
				SIIL[ui.comboBox_Image->currentIndex()].ImageSize,
				SystemPartitionLetter,
				EspInfomationList[ui.comboBox_EfiPartition->currentIndex()]->PartitionInfo->DiskNumber,
				EspInfomationList[ui.comboBox_EfiPartition->currentIndex()]->PartitionInfo->PartitionNumber,
				EspInfomationList[ui.comboBox_EfiPartition->currentIndex()]->Letter,
				SystemPartitionLetter
			).c_str(),
			L"信息核对",
			MB_ICONQUESTION | MB_YESNO
		) != IDYES) {
		AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW][RESTORE]用户取消操作");
		return;
	}

	if (
		MessageBox(
			NULL,
			std::format(L"再次警告：\n与您在手机上的“恢复出厂设置”不同，本软件的重装系统过程不会保留您在驱动器“{0}”的任何数据.\n\n在重装过程开始时，驱动器“{0}”的所有数据都将被不可逆转地摧毁。\n这意味着如果你选择将重要数据存放在驱动器“{0}”上，则在重装系统时都会被清除且不可找回。\n\n我们将您点击“是”视为您知晓这则警告，清楚自己在做什么，以及可能会带来的后果，并同意所有造成的损失均由您承担，开发者不负任何责任！", SystemPartitionLetter).c_str(),
			L"请清楚您在做什么！",
			MB_ICONQUESTION | MB_YESNO
		) != IDYES) {
		AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW][RESTORE]用户取消操作");
		return;
	}

	AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW][RESTORE]用户继续操作");
	bool bStatus = CreatePePartition(
		WorkDirPath + L"\\Data\\WinPE\\boot.wim",
		WorkDirPath + L"\\Data\\WinPE\\boot.sdi",
		ImageFilePathW,
		ui.comboBox_Image->currentIndex(),
		SystemPartitionLetter,
		EspInfomationList[ui.comboBox_EfiPartition->currentIndex()]->Letter,
		(std::vector<CopyFileHandle>)NULL
	);

	if (!bStatus) return;

	if (ui.comboBox_AfterCreateEnviorment->currentIndex() == 0) {
		MessageBox(
			NULL,
			L"创建成功！",
			L"",
			NULL
		);
	}
	else if (ui.comboBox_AfterCreateEnviorment->currentIndex() == 1) {
		AstLog_WriteWarning(LogHandle, L"[EXIT]用户设置“15秒后关机”，开始进行保护措施。");
		this->setVisible(false);

		MessageBoxTimeout(
			NULL,
			L"系统将于15秒后关机，请保存好重要数据。点击“确定”可立即重启电脑",
			L"",
			NULL,
			0,
			15000
		);
		AstLog_WriteWarning(LogHandle, L"[EXIT]系统即将关机，开始保护程序");
		AstLog_WriteWarning(LogHandle, L"[EXIT]程序开始退出！");
		AstLog_StopService(LogHandle);

		system("shutdown -s -t 0");
		while (1) {};
	}
	else if (ui.comboBox_AfterCreateEnviorment->currentIndex() == 2) {
		AstLog_WriteWarning(LogHandle, L"[EXIT]用户设置“15秒后重启”，开始进行保护措施。");
		this->setVisible(false);

		MessageBoxTimeout(
			NULL,
			L"系统将于15秒后重启，请保存好重要数据。点击“确定”可立即重启电脑",
			L"",
			NULL,
			0,
			15000
		);
		AstLog_WriteWarning(LogHandle, L"[EXIT]系统即将重启，开始保护程序");
		AstLog_WriteWarning(LogHandle, L"[EXIT]程序开始退出！");
		AstLog_StopService(LogHandle);

		system("shutdown -r -t 0");
		while (1) {};
	}
}

void AST_QT::pushButtonBackupSystemClicked() {
	//打印日志
	AstLog_WriteMessage(LogHandle, L"[RUNTIME][QT][MAINWINDOW]用户选中按钮：“导航栏->备份系统”");
	ui.MainWindowWidget->setCurrentIndex(2);
	return;
}